package com.qiufenfen.cloud.gateway.test;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Random;

/**
 * @author 飗痕
 * @version 1.0
 * @date 2025-10-27 11:50
 */
public class test{
    public static void main(String[] args) {
        HttpClient client = HttpClient.newHttpClient();
        Random random = new Random();
        // 定义一组预设的电话号码
        long[] phoneNumbers = {15871391676L, 15098001001L,13476453999L, 15623209833L};
        // 循环发送请求
        for (int i = 0; i < 20; i++) {
//            long phoneNumber = random.nextLong() % 7000000000L + 13000000000L;
//            long phoneNumber = 15871391676L;
//            long phoneNumber = i+100L;

// 使用 Random 从数组中随机选择一个
//            long phoneNumber = phoneNumbers[random.nextInt(phoneNumbers.length)];

// 或者生成指定长度的随机字符串
            String randomString = generateRandomChineseName(random);
            System.out.println("生成的随机字符串: " + randomString);


            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create("http://192.168.100.72:8080/msg/publish?msg=" + randomString))
                    .header("Content-Type", "application/json")
                    .GET()
                    .build();

            try {
                HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
                System.out.println("Response: " + response.statusCode());
//                System.out.println("Response: " + response);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static String generateRandomChineseText(Random random, int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            // 中文Unicode范围：0x4E00 - 0x9FFF
//            int codePoint = random.nextInt(0x9FFF - 0x4E00 + 1) + 0x4E00;
            // 限定为常用简体中文范围
            int codePoint = random.nextInt(0x9FA5 - 0x4E00 + 1) + 0x4E00;
            sb.append((char) codePoint);
        }
        return sb.toString();
    }

    public static String generateRandomChineseName(Random random) {
        // 扩展姓氏数组，包含更多常见姓氏
        String[] surnames = {
                "李", "王", "张", "刘", "陈", "杨", "赵", "黄", "周", "吴",
                "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗",
                "梁", "宋", "郑", "谢", "韩", "唐", "冯", "于", "董", "萧"
        };

        // 扩展名字数组，包含更多常用字
        String[] givenNames = {
                "伟", "芳", "娜", "秀英", "敏", "静", "丽", "强", "磊", "军",
                "洋", "勇", "艳", "杰", "娟", "涛", "明", "超", "秀兰", "霞",
                "平", "刚", "桂英", "鹏", "华", "红", "梅", "飞", "鑫", "波",
                "斌", "雪", "慧", "晨", "琳", "凯", "婷", "帅", "文", "建",
                "小明", "小红", "志远", "思雨", "子涵", "浩然", "欣怡", "俊杰", "雅婷", "嘉豪"
        };

        String surname = surnames[random.nextInt(surnames.length)];
        // 生成1-2个字的名字
        int nameLength = random.nextInt(2) + 1;
        StringBuilder givenName = new StringBuilder();

        for (int i = 0; i < nameLength; i++) {
            givenName.append(givenNames[random.nextInt(givenNames.length)]);
        }

        return surname + givenName.toString()+"到此一游";
    }
    public static String generateMeaningfulChineseText(Random random) {
        String[] subjects = {"刘老师", "陈老师", "张老师", "李老师", "王老师"};
        String[] verbs = {"在教室", "在办公室", "在茶水间", "在厕所", "在楼梯间"};
        String[] objects = {"抽烟", "吃饭", "睡觉", "喝水", "敲代码"};

        String subject = subjects[random.nextInt(subjects.length)];
        String verb = verbs[random.nextInt(verbs.length)];
        String object = objects[random.nextInt(objects.length)];

        return subject + verb + object;
    }
}